# Copyright (c) 2020 cgsdfc
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

"Generate a source file using the python module."

DATA = "//astlib:data.pkl"
TOOL = "//astlib:gen_src"
COMMAND = "./$(location {tool}) -t $(location {template}) -o $(location {output}) --data $(location {data})"

def generate_source(name, output, visibility = None):
    template = "{}.mako".format(output)
    native.genrule(
        name = name,
        outs = [output],
        srcs = [template, DATA],
        tools = [TOOL],
        cmd = COMMAND.format(
            tool = TOOL,
            template = template,
            output = output,
            data = DATA,
        ),
    )
